<template>
	<view>
		<view class="oneList" v-for="(item,i) in list">
			<view class="imgBox">
				<image :src="item.pic"></image>
			</view>
			<view>
				<view class="title">{{item.name}}</view>
				<view class="minor">销量：{{item.sales}}</view>
				<view class="minor">库存：{{item.stock}}</view>
				<view class="btnBox between">
					<view>¥{{item.sell_price}}</view>
					<view class="flex">
						<view class="btn flex edit" v-if="pageType==1" @click.stop="handleOperate(item.id,1)">上架</view>
						<view class="btn flex" v-if="pageType==1" @click.stop="handleOperate(item.id,3)">删除</view>
						<view class="btn flex edit" v-else @click.stop="handleOperate(item.id,2)">下架</view>
						<!-- 	<view class="btn flex edit" @click="onSkip('/package/mine/apage')">编辑</view> -->
					</view>
				</view>
			</view>
		</view>
		<view class=" flex-center addressImgBox" v-if="list.length==0">
			<image src="https://wx.2024csnl.com/static/noData.png"></image>
			暂无数据~
		</view>
		<view style="text-align: center;color: #999;" v-if="noMoreData&&list.length!=0">没有更多啦~</view>
	</view>
</template>

<script>
	import {
		merchantGoodSoperate
	} from "../../../api/index.js"
	export default {
		props: {
			noMoreData: {
				type: Boolean,
				defaule: false
			},
			pageType: {
				type: [Number, String]
			},
			list: {
				type: Array,
				default: () => {
					return []
				}
			}
		},

		data() {
			return {

			}
		},
	
		methods: {
			async onMerchantGoodSoperate(id, type) {
				// console.log(id,"tyy",type)
				const res = await merchantGoodSoperate('s=/ApiBusiness/bshopcz', {
					id: id,
					type: type
				})
				// console.log(res,"res---")
				const{msg,status}=res.data
				this.showToast(msg)
				if(status==1){
					setTimeout(()=>{
						uni.$emit('refish',true)
					},2000)
				}

			},
			// 操作
			async handleOperate(id, type) {
				if (type != 3) {
					this.onMerchantGoodSoperate(id, type)
				} else {
					const result = await new Promise(resolve => {
						uni.showModal({
							title: '提示',
							content: '确认删除该商品?',
							confirmColor: '#41644A',
							success(msg) {
								resolve(msg)
							}
						});
					})
					if (result.confirm) {
						// console.log('删除')
						this.onMerchantGoodSoperate(id, type)
					}
				}




			},

		}
	}
</script>

<style lang="scss" scoped>
	.addressImgBox {
		flex-direction: column;
		color: #999;
		padding-top: 20%;

		image {
			width: 400rpx;
			height: 400rpx;
		}
	}

	.btn {
		font-weight: 500;
		font-size: 26rpx;
		width: 116rpx;
		height: 44rpx;
		align-items: center;
		border-radius: 22rpx;
		margin-left: 14rpx;
		justify-content: center;
		border: 1px solid #4ac9d8;
	}

	.edit {
		color: #fff;
		background: #4ac9d8;
	}

	.btnBox {
		color: #3e3a39;
		margin-top: 14rpx;
		font-size: 28rpx;
	}

	.minor {
		color: #999999;
		font-size: 24rpx;
		margin-top: 8rpx;
	}

	.title {
		font-size: 30rpx;
		font-weight: 400;
		color: #333;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
	}

	.oneList {
		border-bottom: 1px solid #F1F1F1;
		padding: 20rpx 20rpx 20rpx;
		display: grid;
		grid-template-columns: 30% 70%;
		grid-gap: 0 30rpx;

		.imgBox {
			width: 210rpx;
			height: 210rpx;

			image {
				width: 100%;
				height: 100%;
				border-radius: 10rpx;
			}
		}

	}
</style>
